﻿@using Pay.DTO
@{
    ViewBag.Title = "商品详情";
    Layout = "~/Views/Shared/_MallLayout.cshtml";
    string shareNo = ViewBag.ShareNo;
    string img_url = ViewBag.img_url;
    product_dto product = ViewBag.Product as product_dto;
    int isShare = !string.IsNullOrEmpty(shareNo) ? 1 : 0;
    bool isLogin = ViewBag.isLogin;
    // long shop_id = ViewBag.ShopId;//商品对应的店铺
    var shop = ViewBag.shop as shop_info_dto;
    var ad = ViewBag.ad as ad_dto;
    long reqShopIdParam = 0;//来源节点商城
    if (Request["shopId"] != null && !string.IsNullOrEmpty(Request["shopId"].ToString())) {
        reqShopIdParam = long.Parse(Request["shopId"].ToString());
    }
    var merchant = ViewBag.merchant as merchant_dto;
    red_user_dto redcord = ViewBag.redcord as red_user_dto;
    string share_url = t_RequestMethod.token_url + Url.Action("ProductDetail", "DistributionMall") + "?productId=" + product.id + "&merchant_no=" + merchant.merchant_no;
    if (reqShopIdParam != 0) {
        share_url += "&shopId=" + reqShopIdParam;
    }
    var likeProduct = ViewBag.likeProduct as List<product_dto>;
    var is_on_sale = (product.audit_status == AuditStatus.PendingAudit || product.audit_status == AuditStatus.Sell) && product.sale_status == SaleStatus.Sell && product.stock > 0;
}
<style>
    .page-details .choicePop .con .disable {
        display: inline-block;
        color: #666;
        text-align: center;
        background-color: #f4f4f4;
        font-size: .5973333333333334rem;
        padding: 0 1.024rem;
        height: 1.28rem;
        line-height: 1.28rem;
        border-radius: .64rem;
        margin: 0 .64rem .4266666666666667rem 0;
        opacity: 0.4;
    }
</style>
<body class="page-details">
    @Html.Partial("_PMallHead")
    <input type="hidden" id="isFromShare" value="@isShare" />
    <div class="swiper-container banner">
        <div class="swiper-wrapper">
            @if (product.image_path != null && product.image_path.Count() > 0) {
                foreach (var item in product.image_path) {
                    <div class="swiper-slide"><img src="@item" alt=""></div>
                }
            } else if (!string.IsNullOrEmpty(product.main_image_url)) {
                <div class="swiper-slide"><img src="@product.main_image_url" alt=""></div>
            }
        </div>
        <div class="swiper-pagination fn26 col-white"></div>
    </div>
    @if (product.activity_ex != null && product.activity_ex.is_activity == true && product.activity_ex.activity_type != EActivityType.ProductMaker) {
        <div class="active bg-white">
            <div class="left fn-left fn28 col-white">
                @if (product.price > 0) {
                    <em>￥</em><em class="fn40">@product.price.ToString("0.##")</em>
                }
                @if (product.price > 0 && product.activity_ex.activity_red_drill > 0) {
                    <span>+</span>
                }
                @if (product.activity_ex.activity_red_drill > 0) {
                    <em class="fn40">@product.activity_ex.activity_red_drill.ToString("0.######")</em> <span>红钻</span>
                }

                @if (product.activity_ex.activity_red_drill == 0) {
                    <span class="through">￥@product.market_price.ToString("0.##")</span>
                }
            </div>
            @if (product.activity_ex.preheat_time != null
             && product.activity_ex.preheat_time < DateTime.Now && product.activity_ex.begin_time > DateTime.Now) {
                <!-- 活动即将开始 -->
                <div class="right cur fn-right fn-center">
                    <i class="ic-active"></i>
                    <span class="col-red fn28 mt15 mb5">活动即将开始</span>
                </div>
            } else if (product.activity_ex.end_time > DateTime.Now) {
                <!-- 活动倒计时 -->
                <div id="activity_countdown_div" class="right fn-right fn-center">
                    <div class="col-red fn28 mt15 mb5">距活动结束</div>
                    <div class="time fn24">
                        <span id="_h0">0</span><span id="_h1">0</span><em>:</em><span id="_m0">0</span><span id="_m1">0</span><em>:</em><span id="_s0">0</span><span id="_s1">0</span>
                    </div>
                </div>
            }
        </div>
    }
    <!--header end-->
    <div class="lt-con">
        @if (!(product.activity_ex != null && product.activity_ex.is_activity == true && product.activity_ex.activity_type != EActivityType.ProductMaker)) {
            <div class="mb20 mt5">
                <span class="col-red">
                    @if (product.product_skus != null && product.product_skus.Count > 1) {
                        var max_price = product.product_skus.Max(s => s.price);
                        var min_price = product.product_skus.Min(s => s.price);
                        if (max_price == min_price) {
                            <em class="fn28">￥</em><em class="fn40">@product.price.ToString("0.##")</em>
                        } else {
                            <em class="fn28">￥</em><em class="fn40">@min_price.ToString("0.##")-@max_price.ToString("0.##")</em>
                        }
                    } else {
                        <em class="fn28">￥</em><em class="fn40">@product.price.ToString("0.##")</em>
                    }
                </span>
                <span class="col-gray fn-right fn26">
                    邮费：   @if (product.freight.GetValueOrDefault(0) > 0) {
                        @(product.freight.GetValueOrDefault(0)) @:元
                    } else {
                        @:包邮
                    }
                </span>
            </div>
        }
        <div class="fn30 mb5">
            @product.name
        </div>
        @if (product.activity_ex != null && product.activity_ex.is_activity == true && product.activity_ex.activity_type != EActivityType.ProductMaker) {
            <div class="fn26 col-gray">
                <span class="col-gray fn26">
                    邮费：   @if (product.freight.GetValueOrDefault(0) > 0) {
                        @(product.freight.GetValueOrDefault(0)) @:元
                    } else {
                        @:包邮
                    }
                </span>
            </div>
        }
    </div>


    @if (ad != null) {
        <img src="@(img_url+ad.img_url)" align="top" alt="@ad.title" onclick="javascript: location.href='@ad.link_url'">
    }

    @if (product.is_seas) {
        <div class="explain fn28 col-red mb10" id="explain">
            <i class="ic-explain fn-left mr20"></i>
            跨境商品说明
            <i class="icon-arrow2 fn-right"></i>
        </div>}

        <div class="bg-white">
            @if (shop.id > 0) {
                <div class="nodeStore block mt20 flex border-bottom">
                    <div class="img mr20 flex-box">
                        <img src="@(!string.IsNullOrEmpty(shop.shop_logo) ? (img_url + shop.shop_logo) : "/Content/css/tokenmall/img/mallHome.png")" alt="">
                    </div>
                    <div class="flex-1">
                        <div class="fn28 mb10">@shop.shop_name</div>
                        <p class="fn-nowrap2 fn26 col-gray2">@shop.remark</p>
                    </div>
                    <div class="mt30">
                        <a href="@Url.Action("Index2", "DistributionMall")?shopId=@shop.id" class="ui-btn ui-btn-red w140">进入节点</a>
                    </div>
                </div>
            }
            @if (likeProduct.Count > 0 && 
                !(product.activity_ex != null && product.activity_ex.is_activity == true &&
                (product.activity_ex.activity_type == EActivityType.ProductOnlyRedDrill || product.activity_ex.activity_type == EActivityType.ProductMaker))) {
                <div class="block">
                    <div class="fn28 mb30 fn-bold">同类推荐</div>
                    <div class="pro">
                        <ul>
                            @foreach (var item in likeProduct) {
                                <li>
                                    <div class="itemBox">
                                        <a href="/DistributionMall/ProductDetail?productId=@item.id">
                                            <div class="img mb20">
                                                <img src="@item.first_image">
                                            </div>
                                            <div class="box">
                                                <p class="tit fn-nowrap2 mb20">@item.name</p>
                                                <p class="fn-nowrap">
                                                    @if (item.price > 0) {
                                                        <span class="col-red">
                                                            <em class="fn26">￥</em>
                                                            <em class="fn30">@item.price.ToString("0.##")</em>
                                                        </span>
                                                    }
                                                    @if (item.price > 0 && (item.activity_ex != null && item.activity_ex.activity_red_drill > 0)) {
                                                        <span class="col-red"></span>
                                                    }
                                                    @if (item.activity_ex != null && item.activity_ex.activity_red_drill > 0) {
                                                        <span class="col-red">
                                                            <em class="fn30">@item.activity_ex.activity_red_drill.ToString("0.######")</em>
                                                            <em class="fn26">红钻</em>
                                                        </span>
                                                    }
                                                </p>
                                            </div>
                                        </a>
                                    </div>
                                </li>
                            }
                        </ul>
                    </div>
                </div>
            }

        </div>
    <div class="tails lt-pb">
        <div class="title fn-center">
            <i></i>
            <span class="fn26 col-gray2">商品详情</span>
            <i></i>
        </div>
        <div>
            @Html.Raw(product.description)
        </div>
    </div>
    <div class="lt-bottom">
        @if (!(product.activity_ex != null && product.activity_ex.is_activity == true &&
                (product.activity_ex.activity_type == EActivityType.ProductMaker || product.activity_ex.activity_type == EActivityType.ProductOnlyRedDrill))) {
            if (reqShopIdParam > 0) {
                <a href="@Url.Action("Index2", "DistributionMall")?shopId=@reqShopIdParam" class="item">
                    <span><i class="icon-merchant1"></i></span>
                    <p class="col-gray">首页</p>
                </a>
            } else if (shop.id > 0) {
                <a href="@Url.Action("Index2", "DistributionMall")?shopId=@shop.id" class="item">
                    <span><i class="icon-merchant"></i></span>
                    <p class="col-gray">节点</p>
                </a>
            }
            @*if (shop_id > 0) {
                    <a href="/ShopInfo/MyShop/@shop_id" class="item">
                        <span><i class="icon-merchant"></i></span>
                        <p class="col-gray">商家</p>
                    </a>
                }*@
            <a href="javascript:void(0)" class="item " id="shoppingCart">
                <span class="">
                    <i class="icon-cart relative"><em class="qt absolute" id="cartCount">0</em></i>
                </span>
                <p class="col-gray">购物车</p>
            </a>
            <a href="javascript:void(0)" class="item mr20" id="share_product">
                <span><i class="icon-share2"></i></span>
                <p class="col-gray">分享</p>
            </a>
            @*<a href="/cart/index" class="item mr20">
                    <span><i class="icon-share2"></i></span>
                    <p class="col-gray">购物车</p>
                </a>*@
        }
        <div class="right flex">
            @if (is_on_sale || (product.activity_ex != null && product.activity_ex.preheat_time != null && product.activity_ex.preheat_time < DateTime.Now && product.activity_ex.begin_time > DateTime.Now)) {
                if (product.activity_ex != null && product.activity_ex.preheat_time != null && product.activity_ex.preheat_time < DateTime.Now && product.activity_ex.begin_time > DateTime.Now) {
                    <a href="javascript:;" class="ui-btn ui-btn-big ui-btn-cancel flex-1 mt10" style="background: #d1d1d1">
                        活动即将开始
                    </a>
                } else {
                    if (!(product.activity_ex != null && product.activity_ex.is_activity == true &&
                         (product.activity_ex.activity_type == EActivityType.ProductMaker || product.activity_ex.activity_type == EActivityType.ProductOnlyRedDrill))) {
                        <a href="javascript:void(0);" class="ui-btn ui-btn-big ui-btn-addCart flex-1 mt10 addCart tokenbuy" id="tokenaddcart">
                            加入购物车
                        </a>
                        <a href="javascript:void(0);" class="ui-btn ui-btn-big ui-btn-red flex-1 mt10 addBuy tokenbuy" id="tokenaddbuy">
                            立即购买
                        </a>
                    } else {
                        <a href="javascript:void(0);" class="ui-btn ui-btn-big ui-btn-red flex-1 mt10 tokenbuy" id="tokenaddbuy">
                            立即购买
                        </a>
                    }

                }
            } else {
                if (!(product.activity_ex != null && product.activity_ex.is_activity == true &&
                      (product.activity_ex.activity_type == EActivityType.ProductMaker || product.activity_ex.activity_type == EActivityType.ProductOnlyRedDrill))) {
                    <a href="javascript:void(0);" class="ui-btn ui-btn-big ui-btn-addCart flex-1 mt10 addCart" style="background: #e4e4e4">
                        加入购物车
                    </a>
                    <a href="javascript:void(0);" class="ui-btn ui-btn-big ui-btn-red flex-1 mt10 addBuy" style="background: #d1d1d1">
                        立即购买
                    </a>
                } else {
                    <a href="javascript:void(0);" class="ui-btn ui-btn-big ui-btn-red flex-1 mt10" style="background: #d1d1d1">
                        立即购买
                    </a>
                }
            }
        </div>
    </div>
    <!-- 点击购买弹窗 -->
    <div class="black "></div>
    <div class="choicePop" id="pop1">
        <div class="box" id="popbox">
            @{ var product_skuinfo = product.sku_infos;
                var sku_info_names = product_skuinfo.Select(s => s.name).ToList();
            }
            @if (product.product_skus.Count > 0) {
                var firstsku = product.product_skus.FirstOrDefault();

                <div class="top">
                    <a href="javascript:;" class="icon-close"></a>
                    <span class="img fn-left mr20">
                        <img width="60" height="60" src="@product.first_image" />
                    </span>
                    <div class="tit">
                        <p class="mb5">
                            <!--有活动时显示-->
                            <span id="sku_select_price_activity_span" class="fn-bold mr20" style="@(product.activity_ex != null && product.activity_ex.is_activity == true ? "" : "display:none;")">
                                <em class="activity fn24">活动价格</em>
                                <span class="col-red">
                                    <span id="sku_cash_span" style="@(product.price > 0 ? "" : "display:none;")">
                                        <em class="fn22">￥</em>
                                        <em class="fn32" id="product_activity_price">@product.price</em>
                                    </span>
                                    <span id="sku_add_span" style="@(product.price > 0 && product.activity_ex != null && product.activity_ex.activity_red_drill > 0 ? "" : "display:none;")">+</span>
                                    <span id="sku_red_drill_span" style="@(product.activity_ex != null && product.activity_ex.activity_red_drill > 0 ? "" : "display:none;")">
                                        <em class="fn32" id="product_red_drill">@(product.activity_ex != null ? product.activity_ex.activity_red_drill : 0)</em> <em class="fn22">红钻</em>
                                    </span>
                                </span>
                            </span>
                            <!--无活动时显示-->
                            <span id="sku_select_price_span" class="fn-bold mr20" style="@(product.activity_ex != null && product.activity_ex.is_activity == true ? "display:none;" : "")">
                                价格: <span class="col-red">
                                    <em class="fn22">￥</em>
                                    <em class="fn32" id="product_total_price">@product.price</em>
                                </span>
                            </span>
                        </p>
                        <p class="col-gray">库存: <em id="product_stock">@product.stock</em>@(string.IsNullOrWhiteSpace(product.unit) || product.unit == "null" ? "件" : product.unit)</p>
                        <p class="mt10"><em>请选择：</em>  <em id="product_sku_name" data-selector="0" data-skupath="" data-skuid="0"> @(string.Join(" ", sku_info_names.ToArray()))</em></p>
                    </div>
                </div>
                <div class="popContent">
                    @foreach (var item in product_skuinfo) {
                        <div class="con" data-groupid="@item.id" data-group-name="@item.name" data-name-selected="0">
                            <div>
                                <p class="fn-bold fn28">@item.name</p>
                            </div>
                            @*@{var first = item.sku_values.FirstOrDefault();}*@
                            @foreach (var sku in item.sku_values) {
                                <span class="a " data-skuid="@(sku.id>0?sku.id.ToString():sku.hn_id)" data-skuprice="">@sku.name</span>
                            }
                        </div>
                    }

                </div>
            }
            <div class="quantity">
                <span class="fn28 fn-bold">
                    购买数量
                </span>
                <div class="num">
                    <span class="min">-</span>
                    <input id="buy_product_num" class="text_box product_input_number" name="" type="text" value="1" readonly unselectable="on" onfocus="this.blur()" />
                    <span class="add">+</span>
                </div>
            </div>
            <div class="btnBox flex">
                @if (!(product.activity_ex != null && product.activity_ex.is_activity == true &&
                (product.activity_ex.activity_type == EActivityType.ProductMaker || product.activity_ex.activity_type == EActivityType.ProductOnlyRedDrill))) {
                    <a href="javascript:addcart();" class="ui-btn ui-btn-big ui-btn-addCart flex-1 mt10 addCart" id="addcart">
                        加入购物车
                    </a>
                    <a href="javascript:confirmBuy();" class="ui-btn ui-btn-big ui-btn-red flex-1 mt10 addBuy" id="confirmBuy">
                        @(product.activity_ex != null && product.activity_ex.is_activity == true ? "活动价购买" : "立即购买")
                    </a>
                } else {
                    <a href="javascript:confirmBuy();" class="ui-btn ui-btn-buy flex-1" id="confirmBuy">
                        @(product.activity_ex != null && product.activity_ex.is_activity == true ? "活动价购买" : "立即购买")
                    </a>
                }


            </div>
        </div>
    </div>
    @if (product.is_seas) {
        Html.RenderPartial("_Description");
    }
    @if (!is_on_sale && !(product.activity_ex != null && product.activity_ex.preheat_time != null && product.activity_ex.preheat_time < DateTime.Now && product.activity_ex.begin_time > DateTime.Now)) {
        <div class="sold fn-center col-white fn30">
            商品已经卖光了~看看其他的！
        </div>
        <div class="soldOut">
            <div class="bg-white" style="width:100%;">
                <div class="block">
                    <div class="top fn30 border-bottom mb30">
                        商品已经卖光了~看看其他的！
                        <span class="fn-right">
                            <i class="icon-close j-close"></i>
                        </span>
                    </div>
                    @if (likeProduct.Count > 0 && (!(product.activity_ex != null && product.activity_ex.is_activity == true &&
                         (product.activity_ex.activity_type == EActivityType.ProductMaker || product.activity_ex.activity_type == EActivityType.ProductOnlyRedDrill)))) {
                        <div class="fn30 mb30">同类推荐</div>
                        <div class="pro">
                            <ul>
                                @foreach (var item in likeProduct) {
                                    <li>
                                        <div class="itemBox">
                                            <a href="/DistributionMall/ProductDetail?productId=@item.id">
                                                <div class="img mb20">
                                                    <img src="@item.first_image">
                                                </div>
                                                <div class="box">
                                                    <p class="tit fn-nowrap2 mb20">@item.name</p>
                                                    <p class="fn-nowrap">
                                                        @if (item.price > 0) {
                                                            <span class="col-red">
                                                                <em class="fn26">￥</em>
                                                                <em class="fn30">@item.price.ToString("0.##")</em>
                                                            </span>
                                                        }
                                                        @if (item.price > 0 && (item.activity_ex != null && item.activity_ex.activity_red_drill > 0)) {
                                                            <span class="col-red"></span>
                                                        }
                                                        @if (item.activity_ex != null && item.activity_ex.activity_red_drill > 0) {
                                                            <span class="col-red">
                                                                <em class="fn30">@item.activity_ex.activity_red_drill.ToString("0.######")</em>
                                                                <em class="fn26">红钻</em>
                                                            </span>
                                                        }
                                                    </p>
                                                </div>
                                            </a>
                                        </div>
                                    </li>
                                }
                            </ul>
                        </div>
                    }
                </div>

            </div>
        </div>
    }

    <div class="mod-popFx popFx trans_5 j-sharePro">
        <i class="icon-close2 j-close"></i>
        <div class="popView">
            <div class="top">
                <img src="" alt="" id="popimg">
            </div>
        </div>
        <div class="tbnBox">
            <a class="btn j-copy" data-clipboard-action="copy" data-clipboard-target="#foo" href="javascript:;">复制商品链接</a>
            <a class="btn" href="#" id="saveimg" download="">保存图片</a>
            <input type="text" class="share_code fn-hide" readonly="readonly" id="foo" value="" />
        </div>
    </div>
    <input type="hidden" id="short_description_input" value="@(string.IsNullOrWhiteSpace(product.short_description)?product.name:product.short_description)" />
    <input type="hidden" id="product_name_input" value="@product.name" />
    <input type="hidden" id="share_url_input" value="@share_url" />
    <link href="~/Content/css/tokenmall/css/swiper.min.css" rel="stylesheet" />
    <script src="~/Scripts/tokenmall/swiper.min.js"></script>
    <script src="~/Scripts/clipboard.min.js"></script>
    <script src="~/Scripts/token-common.js"></script>
    <style>
        .choicePop .btnBox {
            overflow: hidden;
        }

        .choicePop .ui-btn-buy {
            width: 49%;
            float: left;
        }

            .choicePop .ui-btn-buy:nth-child(2) {
                float: right;
            }
    </style>

    <script type="text/javascript">


        //function tokenaddcart() {
        //    $('.black').addClass('cur');
        //    $('#pop1').animate({ bottom: 0 }, 20);
        //    $("#addcart").show();
        //    $("#confirmBuy").show();
        //}
        //function tokenaddbuy() {
        //    $('.black').addClass('cur');
        //    $('#pop1').animate({ bottom: 0 }, 20);
        //    $("#addcart").hide();
        //    $("#confirmBuy").show();
        //}
        $(function () {

            try {
                if (browser.versions.ios) {
                    window.webkit.messageHandlers.NoShareUrl.postMessage('');
                } else if (browser.versions.android) {
                    androidfuntion.NoShareUrl();
                }
            } catch (e) {

            }
              @if (merchant.id > 0) {
               <text>
               $.get('/DistributionMall/GetCartCount', function (result) {
                if (result.result_code == 1000) {
                    $("#cartCount").text(result.data);
                    if (Number(result.data) == 0) {
                        $("#cartCount").hide();
                    } else {
                        $("#cartCount").show();
                    }
                }
                })
               </text>
                }
            countTime();
            var skus=@Html.Raw(product.product_skus.ToJson());
            SelectSku(skus);



            // 立即购买
            var windHeight = $(window).height();
            $('.choicePop').css({ bottom: -windHeight });
            $('.black,.icon-close').click(function () {
                $('.black').removeClass('cur');
                $('#pop1').animate({ bottom: -windHeight });
            })
            $('.tokenbuy').click(function () {
                $('.black').addClass('cur');
                $('#pop1').animate({ bottom: 0 }, 20);
                //if ($(this).hasClass('addCart')) {
                //    $("#addcart").show();
                //    $("#confirmBuy").hide();
                //}
                //else {
                //    $("#addcart").hide();
                //    $("#confirmBuy").show();
                //}
                console.log(1);
            })
            var sku_selected = [];
            // 选中状态
            $('.con span').on("click", function () {
                getProduct();
                var that = $(this);
                if (that.hasClass('disable')) return;
                var sku_id = that.attr("data-skuid");
                that.toggleClass('cur');
                if (that.hasClass('cur')) {
                    that.siblings('.a').each(function (i, item) {
                        if ($(item).hasClass('cur')) {
                            var index = sku_selected.indexOf($(item).attr('data-skuid'));
                            if (index > -1) {
                                sku_selected.splice(index, 1);
                            }}
                    });
                    that.siblings('.a').removeClass('cur');

                }
                if (that.parent('.con').find('span').hasClass('cur')) {
                    that.parent(".con").attr("data-name-selected", 1);
                    sku_selected.push(sku_id);
                }
                else {
                    that.parent(".con").attr("data-name-selected", 0);
                    var index = sku_selected.indexOf(sku_id);
                    if (index > -1) {
                        sku_selected.splice(index, 1);
                    }
                }
                var con = $(".popContent .con");
                var product_sku_name = '';
                con.each(function (i, item) {
                    if ($(item).attr("data-name-selected") == 0) {
                        product_sku_name += $(item).attr('data-group-name') + ' ';
                    }
                });

                var sku_select = [];
                for (var i = 0; i < skus.length; i++) {
                    if (skus[i].stock <= 0) {
                        var sku_path = skus[i].sku_path.split('-');
                        for (var s = 0; s < sku_selected.length; s++) {
                            if ($.inArray(sku_selected[s], sku_path) > -1) {
                                for (var n = 0; n < sku_path.length; n++) {
                                    if (sku_path[n] != sku_selected[s]) { sku_select.push(sku_path[n]); }
                                }
                            }
                        }

                    }

                }
                con.find("span").each(function (i, item) {
                    if ($.inArray($(item).attr("data-skuid"), sku_select) > -1) {
                        $(item).removeClass('a').addClass("disable");
                    }
                    else {
                        if (sku_selected.length > 1) {
                            if ($(item).hasClass('disable')) {
                                $(item).removeClass('disable').addClass('a');
                            }
                        }

                    }


                });
                if (product_sku_name.length == 0) {
                    var path = [];
                    con.find('span').each(function (i, item) {
                        if ($(item).hasClass('cur')) {
                            product_sku_name += $(item).text() + ' ';
                            path.push($(item).attr("data-skuid"));
                        }
                    });
                    $("#product_sku_name").prev().text("已选择:");
                    $("#product_sku_name").text(product_sku_name);
                    var skupath = path.join('-');
                    $("#product_sku_name").attr("data-skupath", skupath);
                    for (var i = 0; i < skus.length; i++) {
                        if (skupath == skus[i].sku_path) {
                            var buy_product_num = parseInt($("#buy_product_num").val())
                            $("#product_sku_name").attr("data-skuid", skus[i].id)
                            $("#buy_product_num").val(1);
                            $("#product_stock").text(skus[i].stock);
                            if (skus[i].activity_ex != null && skus[i].activity_ex.is_activity == true) {//选择的规格有活动
                                $("#sku_select_price_activity_span").show();
                                $("#sku_select_price_span").hide();

                                $("#sku_select_price_activity_span #product_activity_price").text(skus[i].price);
                                $("#sku_select_price_activity_span #product_red_drill").text(skus[i].activity_ex.activity_red_drill);

                                if (skus[i].price > 0) {
                                    $("#sku_cash_span").show();
                                } else {
                                    $("#sku_cash_span").hide();
                                }

                                if (skus[i].price > 0 && skus[i].activity_ex.activity_red_drill > 0) {
                                    $("#sku_add_span").show();
                                } else {
                                    $("#sku_add_span").hide();
                                }

                                if (skus[i].activity_ex.activity_red_drill > 0) {
                                    $("#sku_red_drill_span").show();
                                } else {
                                    $("#sku_red_drill_span").hide();
                                }

                                $("#confirmBuy").html("活动价购买");


                            } else {//选择的规格无活动
                                $("#sku_select_price_activity_span").hide();
                                $("#sku_select_price_span").show();

                                $("#product_total_price").text(skus[i].price);

                                $("#confirmBuy").html("立即购买");
                            }
                            break;
                        }
                    }
                }
                else {
                    $("#product_sku_name").attr("data-skupath", "");
                    $("#product_sku_name").prev().text("请选择:");
                    $("#product_sku_name").text(product_sku_name);
                }

                //getsku();
            })
            // 商品卖光了
            $('.soldOut .j-close').click(function () {
                $('.soldOut').hide();
            })

            // 点击加减
            $(".add").click(function () {
                var t = $(this).parent().find('input[class*=text_box]');
                //有规格
                if ($("#popbox").children('.top').length > 0) {
                    var product_stock = parseInt($("#product_stock").text())
                    if ($("#product_sku_name").attr("data-skupath").length >0 && parseInt(t.val()) >= product_stock) {
                        layer.msg("数量超出范围");
                    }
                    else {
                        t.val(parseInt(t.val()) + 1)
                    }
                }
                else {
                    if (parseInt(t.val()) >= @product.stock) {
                        layer.msg("数量超出范围");
                    }
                    else {
                        t.val(parseInt(t.val()) + 1)
                    }
                }
            })
            $(".min").click(function () {
                var t = $(this).parent().find('input[class*=text_box]');
                t.val(parseInt(t.val()) - 1)
                if (parseInt(t.val()) < 1) {
                    t.val(1);
                }
            })
            @*function getsku() {
             var sku_paths = [];
                $(".con .cur").each(function (i, item) {
                sku_paths.push($(item).attr("data-skuid"));
            });
             var sku_path = sku_paths.join('-')
                $.get("/DistributionMall/SkuInfo", { product_id: @product.id, sku_path: sku_path }, function (response) {
                var data = response.data;
                $("#product_stock").html(data.stock);
                $("#product_sku_name").html(data.sku_name);
                $("#product_total_price").html("￥" + data.price);
            });
            }*@
            function getProduct() {
                $.get("/DistributionMall/GetProduct", { id: @product.id }, function (response) {
                    if (response.result_code == 1000) {
                        if (response.data.product_skus.length == skus.length) {
                            skus = response.data.product_skus;
                        }
                        else {
                            location.reload();
                        }
                    }
            });
            }
            function SelectSku(skus) {
                var that = $(".popContent .con");
                var sku_path = '';
                that.each(function (i, item) {
                    if (i != 0) {
                        $(item).find('span').each(function (n, nitem) {
                            if (n== 0) {
                                sku_path += "-"+ $(nitem).attr("data-skuid") ;
                            }
                        });
                    }
                });
                that.first().find("span").each(function (i, item) {
                    var first_skuid = $(item).attr("data-skuid");
                    var path = $(item).attr("data-skuid") + sku_path;
                    var flag = false;//规格都没有库存
                    for (var i = 0; i < skus.length; i++) {
                        if (skus[i].sku_path.indexOf(first_skuid) > -1) {
                            if (skus[i].stock > 0) {
                                flag = true;
                                break;
                            } else {
                                flag = false;
                            }
                        }

                    }
                    if (flag === false) {
                        $(item).removeClass('a').addClass('disable');
                    }
                });

            }
              $("#shoppingCart").click(function () {
                  if (@merchant.id<= 0) {
                      var loginResult = isLogin();
                      if (!loginResult)
                          return loginResult;
                      location.href = "/home/login?returnUrl=@Request.Url"; return;
                  }
                  else {
                      location.href = '/cart/index';
                  }
            })
            //分享
            $("#share_product").click(function () {
                  if (@merchant.id<= 0) {
                    var loginResult = isLogin();
                    if (!loginResult)
                        return loginResult;
                    location.href = "/home/login?returnUrl=@Request.Url"; return;
                }
                var that = $(this);
                var obj = {};
                obj.name =@merchant.id> 0 ? '@merchant.name' : '';
                @{   string head_img = (string.IsNullOrEmpty(merchant.photo) ? "http://" + Request.Url.Authority + "/Content/images/my/icon.png" : string.Format("{0}{1}", img_url, merchant.photo));}
                obj.head_img_url = @merchant.id> 0 ? '@head_img' : '';
                obj.main_image_url = '@product.main_image_url';
                obj.title = "@product.name.Replace("\n", "").Replace("\r", "").Replace("\t", "")";
                obj.cost_price ='@product.market_price';
                obj.price = '@(product.price.ToString("0.##"))';
                obj.red_drill ='@((product.activity_ex != null ? product.activity_ex.activity_red_drill : 0).ToString("0.######"))'
                obj.invitation_code = '@redcord.invitation_code';
                var url = 'http://' + '@Request.Url.Authority' + '/DistributionMall/ProductDetail?productId=' + @product.id;
                obj.share_url = @merchant.id> 0 ? url + '&merchant_no=' + '@merchant.merchant_no' : url;
                try {
                    var data = JSON.stringify(obj);
                    if (browser.versions.ios) {
                        if (isIOSAppNewBrowser != undefined && isIOSAppNewBrowser == true) {
                            window.webkit.messageHandlers.commodityShare.postMessage(data);
                            window.webkit.messageHandlers.NoShareUrl.postMessage('');
                        } else {
                            commodityShare(data)
                        }
                    } else if (browser.versions.android) {
                        androidfuntion.commodityShare(data)
                        androidfuntion.NoShareUrl();
                    }
                } catch (e) {
                    //$('.black').addClass('cur');
                    $('.popFx').animate({ bottom: "0" });
                    var img_url = '/DistributionMall/ImageMerge?product_id=' +@product.id;
                    img_url =@merchant.id> 0 ? img_url + '&merchant_no=' + '@merchant.merchant_no' : img_url;
                    $("#popimg").attr('src', img_url);
                    $('.share_code').val(obj.share_url);
                    $("#saveimg").attr('href', img_url);
                    $("#saveimg").attr('download', obj.name + '.jpg');
                }
            })
            $('.j-copy').click(function () {
                var clipboard = new ClipboardJS('.j-copy');
                clipboard.on('success', function (e) {
                    layer.msg("复制成功");
                });

                clipboard.on('error', function (e) {
                    console.log(e);
                });
            });

            $('.j-close').click(function () {
                $('.popFx').animate({ bottom: "-100%" });
                //$('.black').removeClass('cur');
            })
            // 说明
            $('#explain').click(function () {
                $('.black').addClass('cur');
                $('#pop2').animate({ bottom: -1 }, 20);
            })
            $('.black').click(function () {
                $('.black').removeClass('cur');
                $('#pop2').animate({ bottom: -$(window).height() });
            })

        })
        var flag = false;
        function addcart() {
            if (flag) return;

              if (@merchant.id<= 0) {
                    var loginResult = isLogin();
                    if (!loginResult)
                        return loginResult;
                    location.href = "/home/login?returnUrl=@Request.Url"; return;
            }
            var skupath = '';
            var sku_id = 0;
            var merchant_no = '@shareNo';
            if ($("#popbox").children('.top').length>0) {
                if ($("#product_sku_name").attr("data-skupath").length == 0) {
                    layer.msg("请选择:" + $("#product_sku_name").text());
                    return;
                }
                else {
                    skupath = $("#product_sku_name").attr("data-skupath");
                    sku_id = $("#product_sku_name").attr("data-skuid");
                }
            }
            flag = true;
            var num = $("#buy_product_num").val();
            $.post("/cart/AddCart", { product_id:@product.id, num: num, sku_id: sku_id, merchant_no: merchant_no }, function (result) {
                layer.msg(result.result_msg);
                if (result.result_code == 1000) {
                    var cartCount = parseInt($("#cartCount").text());

                    $("#cartCount").text(cartCount + parseInt(num));
                    if (Number(cartCount + parseInt(num)) == 0) {
                        $("#cartCount").hide();
                    } else {
                        $("#cartCount").show();
                    }
                    $('.black').removeClass('cur');
                    $('#pop1').animate({ bottom: -$(window).height() });

                }
                flag = false;

            });
        }
        function confirmBuy() {
            if (flag) return;

            var skupath = '';
            var sku_id = 0;
            if ($("#popbox").children('.top').length > 0) {
             if ($("#product_sku_name").attr("data-skupath").length == 0) {
                 layer.msg("请选择:" + $("#product_sku_name").text());
                 return;
             }
             else {
                 skupath = $("#product_sku_name").attr("data-skupath");
                 sku_id = $("#product_sku_name").attr("data-skuid");
             }
         }
            var isMakerProduct = '@(product.activity_ex != null && product.activity_ex.is_activity == true && product.activity_ex.activity_type == EActivityType.ProductMaker ? 1 : 0)';//是创客商品，不允许匿名购买
            var isLogin = '@isLogin';
            if (isLogin == 'False') {
                if (isMakerProduct == '1') {//未登录，购买创客商品
                    try {
                        if (browser.versions.ios) {
                          window.webkit.messageHandlers.loginAction.postMessage('');
                        } else if (browser.versions.android) {
                          androidfuntion.loginAction();
                        }
                        } catch (e) {
                            window.location.href = "/home/login?returnUrl=@WebHelper.UrlEncode(Request.Url.ToString())";
                        }
                    return false;
                }
                swal({
                    title: "您还未登录拓垦需要登录后购买吗？",
                    text: "不登录也可以购买！",
                    showCancelButton: true,
                    confirmButtonColor: "",
                    confirmButtonText: "确定",
                    cancelButtonText: "匿名购买",
                    closeOnConfirm: false
                    //设置closeOnConfirm: false，下面二次确认按钮被点击后才会关闭模态框
                },
                    function (isConfirm) {
                        if (isConfirm) {
                            try {
                                if (browser.versions.ios) {
                                    window.webkit.messageHandlers.loginAction.postMessage('');
                                } else if (browser.versions.android) {
                                    androidfuntion.loginAction();
                                }
                            } catch (e) {
                                window.location.href = "/home/login?returnUrl=@WebHelper.UrlEncode(Request.Url.ToString())";
                            }
                        } else {
                            flag = true;
                            var buy_product_num = $("#buy_product_num").val();
                           // window.location.href = '/Order/ConfirmOrder?productId_param=@product.id&num_param=' + buy_product_num + "&skupath=" + skupath;
                            addBuy(@product.id, buy_product_num, sku_id, '@shareNo');
                        }
                    });
            } else {
                flag = true;
                var buy_product_num = $("#buy_product_num").val();
                //window.location.href = '/Order/ConfirmOrder?productId_param=@product.id&num_param=' + buy_product_num + "&skupath=" + skupath;
                addBuy(@product.id, buy_product_num, sku_id, '@shareNo');
            }
            @*var buy_product_num = $("#buy_product_num").val();
            window.location.href = '/Order/ConfirmOrder?productId_param=@product.id&num_param=' + buy_product_num;*@
        }
        function addBuy(product_id, num, sku_id,merchant_no) {
            $.post("/order/AddBuy", {
                model: [{ product_id: product_id, num: num, sku_id: sku_id, merchant_no: merchant_no,shop_id:@product.merchant_id }],
                type: 0 }, function (result) {
                flag = false;
                if (result.result_code == 1000) {
                    window.location.href = '/Order/ConfirmOrder';
                    $('.black').removeClass('cur');
                    $('#pop1').animate({ bottom: -windHeight });
                }
                else {
                    layer.msg(result.result_msg);
                }
            });
        }
    </script>

    <script type="text/javascript">
           var bannerSwiper = new Swiper('.banner', {
            loop: true,
            pagination: {
                el: '.swiper-pagination',
                type: 'fraction',
                renderFraction: function (currentClass, totalClass) {
                    return '<span class="' + currentClass + '"></span>' + '/' + '<span class="' + totalClass + '"></span>';
                },
            },
        });
        function checkTime(i) {
            if (i < 10) {
                i = '0' + i;
            }
            return i;
        }

        function countTime() {
            if ($("#activity_countdown_div") == undefined || $("#activity_countdown_div") == null || $("#activity_countdown_div").length == 0)//没有倒计时
                return;
            //获取当前时间
            var date = new Date();
            var now = date.getTime();
            //设置截止时间
            var endDate = new Date('@((product.activity_ex != null && product.activity_ex.end_time > DateTime.Now) ? product.activity_ex.end_time.ToString("yyyy/MM/dd HH:mm:ss") : DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"))');
            var end = endDate.getTime();
            //时间差
            var leftTime = end - now;
            //定义变量 d,h,m,s保存倒计时的时间
            var d, h, m, s;
            if (leftTime >= 0) {
                d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
                h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
                h += d * 24;
                m = Math.floor(leftTime / 1000 / 60 % 60);
                s = Math.floor(leftTime / 1000 % 60);
            }
            if (now > end) {
                d = "00";
                h = "00";
                m = "00";
                s = "00";
                return;
            }
            d = checkTime(d);
            h = checkTime(h);
            m = checkTime(m);
            s = checkTime(s);
            h = String(h).split('');
            m = String(m).split('');
            s = String(s).split('');
            // document.getElementById("_d").innerHTML = d+"天";
            document.getElementById("_h0").innerHTML = h[0];
            document.getElementById("_h1").innerHTML = h[1];
            document.getElementById("_m0").innerHTML = m[0];
            document.getElementById("_m1").innerHTML = m[1];
            document.getElementById("_s0").innerHTML = s[0];
            document.getElementById("_s1").innerHTML = s[1];
            setTimeout(countTime, 1000);
        }
    </script>
</body>


